

package com.hazelcast.client.impl.protocol.codec.custom;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.Generated;
import com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil;
import com.hazelcast.client.impl.protocol.codec.builtin.CustomTypeFactory;
import com.hazelcast.client.impl.protocol.codec.builtin.StringCodec;

import static com.hazelcast.client.impl.protocol.ClientMessage.BEGIN_FRAME;
import static com.hazelcast.client.impl.protocol.ClientMessage.END_FRAME;
import static com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil.fastForwardToEndFrame;
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*;

@SuppressWarnings("unused")
@Generated("1a9f3522ef5728b2555df4fd03101d99")
public final class VectorIndexConfigCodec {
    private static final int METRIC_FIELD_OFFSET = 0;
    private static final int DIMENSION_FIELD_OFFSET = METRIC_FIELD_OFFSET + INT_SIZE_IN_BYTES;
    private static final int MAX_DEGREE_FIELD_OFFSET = DIMENSION_FIELD_OFFSET + INT_SIZE_IN_BYTES;
    private static final int EF_CONSTRUCTION_FIELD_OFFSET = MAX_DEGREE_FIELD_OFFSET + INT_SIZE_IN_BYTES;
    private static final int USE_DEDUPLICATION_FIELD_OFFSET = EF_CONSTRUCTION_FIELD_OFFSET + INT_SIZE_IN_BYTES;
    private static final int INITIAL_FRAME_SIZE = USE_DEDUPLICATION_FIELD_OFFSET + BOOLEAN_SIZE_IN_BYTES;

    private VectorIndexConfigCodec() {
    }

    public static void encode(ClientMessage clientMessage, com.hazelcast.config.vector.VectorIndexConfig vectorIndexConfig) {
        clientMessage.add(BEGIN_FRAME.copy());

        ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[INITIAL_FRAME_SIZE]);
        encodeInt(initialFrame.content, METRIC_FIELD_OFFSET, vectorIndexConfig.getMetric());
        encodeInt(initialFrame.content, DIMENSION_FIELD_OFFSET, vectorIndexConfig.getDimension());
        encodeInt(initialFrame.content, MAX_DEGREE_FIELD_OFFSET, vectorIndexConfig.getMaxDegree());
        encodeInt(initialFrame.content, EF_CONSTRUCTION_FIELD_OFFSET, vectorIndexConfig.getEfConstruction());
        encodeBoolean(initialFrame.content, USE_DEDUPLICATION_FIELD_OFFSET, vectorIndexConfig.isUseDeduplication());
        clientMessage.add(initialFrame);

        CodecUtil.encodeNullable(clientMessage, vectorIndexConfig.getName(), StringCodec::encode);

        clientMessage.add(END_FRAME.copy());
    }

    public static com.hazelcast.config.vector.VectorIndexConfig decode(ClientMessage.ForwardFrameIterator iterator) {
        // begin frame
        iterator.next();

        ClientMessage.Frame initialFrame = iterator.next();
        int metric = decodeInt(initialFrame.content, METRIC_FIELD_OFFSET);
        int dimension = decodeInt(initialFrame.content, DIMENSION_FIELD_OFFSET);
        int maxDegree = decodeInt(initialFrame.content, MAX_DEGREE_FIELD_OFFSET);
        int efConstruction = decodeInt(initialFrame.content, EF_CONSTRUCTION_FIELD_OFFSET);
        boolean useDeduplication = decodeBoolean(initialFrame.content, USE_DEDUPLICATION_FIELD_OFFSET);

        java.lang.String name = CodecUtil.decodeNullable(iterator, StringCodec::decode);

        fastForwardToEndFrame(iterator);

        return CustomTypeFactory.createVectorIndexConfig(name, metric, dimension, maxDegree, efConstruction, useDeduplication);
    }
}
